package chapter9;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/9 8:57
 */
class WaveForm {
    private static long counter;
    private final long id = counter++;

    @Override
    public String toString() {
        return "Waveform " + id;
    }
}

class Filter {
    public String name() {
        return getClass().getSimpleName();
    }

    public WaveForm process(WaveForm input) {
        return input;
    }
}

class LowPass extends Filter {
    double cutoff;

    public LowPass(double cutoff) {
        this.cutoff = cutoff;
    }
}

class HighPass extends Filter {
    double cutoff;

    public HighPass(double cutoff) {
        this.cutoff = cutoff;
    }
}

class BandPass extends Filter {
    double lowCutOff, highCutOff;

    public BandPass(double lowCutOff, double highCutOff) {
        this.lowCutOff = lowCutOff;
        this.highCutOff = highCutOff;
    }
}

class FilterAdapter implements Processor {

    private Filter filter;

    public FilterAdapter(Filter filter) {
        this.filter = filter;
    }

    @Override
    public String name() {
        return filter.name();
    }

    @Override
    public Object process(Object input) {
        return filter.process((WaveForm) input);
    }
}

public class FilterProcessor {
    public static void main(String[] args) {
        WaveForm waveForm = new WaveForm();
        Apply.process(new FilterAdapter(new LowPass(1.0)), waveForm);
        Apply.process(new FilterAdapter(new HighPass(1.0)), waveForm);
        Apply.process(new FilterAdapter(new BandPass(1.0, 2.0)), waveForm);
    }
}
